<html>
<head>
<title>Gearing up</title>
<script src="js/native_core.js"></script>
<script src="js/ajax.js"></script>
<script type="text/javascript">
var message="Please wait while we configure your app for seamless content delivery.";
var len=message.length-1;
var i=0;
var end=0;
function showMess()
{
if(end!=1)
{
document.getElementById('cursor').innerHTML="";
document.getElementById('text').innerHTML+=message.charAt(i);
document.getElementById('cursor').innerHTML="|";
}
else
{
document.getElementById('text1').innerHTML+=message.charAt(i);
}
if(i==len)
{
if(end==1)
{
setTimeout("makeEmailLink()",2000);
return;
}
end=1;
document.getElementById('text').innerHTML+='<br/><div id="text1"></div>';
document.getElementById('cursor').innerHTML="";
i=-1;
message="-The Admin Team";
len=message.length-1;
}
i++;
refreshTimeout();
}

function refreshTimeout()
{
setTimeout("showMess()",Math.floor((Math.random()*50)+100));
}

function makeEmailLink()
{
document.getElementById('text1').innerHTML='-The <a href="mailto:sriramdasty7@gmail.com">Admin</a> Team</a>';
setTimeout("readyNext()",5000);
}
function validate()
{
var page="validateotp.php";
var args="user="+nativeGetUserName()+"&otp="+document.getElementById('otp').value;
var xmlhttp=loadAjax();
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4)
    {
    if(xmlhttp.responseText=="ok") {
document.getElementById('loader').innerHTML="";
document.getElementById('text').innerHTML="<font color=green><b>Configuration successful</b></font><a href=main.php>Proceed to Main</a>";
}
	else alert("no");
    }
  }
if(args!="" || args!=null) args+="&rand="+Math.random();
else args="rand="+Math.random();
xmlhttp.open("GET",page+"?"+args,true);
xmlhttp.send();
}
function readyNext()
{
if(ready!=1) {setTimeout("readyNext()",500); return;}
/*
document.getElementById('text').innerHTML="";
document.getElementById('text').innerHTML="Please check your email for One Time Password which is mailed to you<br/><br/>";
document.getElementById('text').innerHTML+="<input type=text id=otp>&nbsp;</input><input type=button value=Validate onclick=\"javascript:validate()\;\"></input>";
*/
window.location.assign("main.php");
}
function getKey()
{
var page="rsa.php";
var args="user="+nativeGetUserName();
var xmlhttp=loadAjax();
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4)
    {
    nativeCreateFileWithData(key_file,xmlhttp.responseText);
    setTimeout("testEnc()",22000);
    }
  }
if(args!="" || args!=null) args+="&rand="+Math.random();
else args="rand="+Math.random();
xmlhttp.open("GET",page+"?"+args,true);
xmlhttp.send();
}
function testEnc()
{
var page="handshake.php";
var args="key="+nativeGetFileData(key_file)+"&user="+nativeGetUserName();
var xmlhttp=loadAjax();
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4)
    {
//alert(xmlhttp.responseText);
ready=1;
    }
  }
if(args!="" || args!=null) args+="&rand="+Math.random();
else args="rand="+Math.random();
xmlhttp.open("GET",page+"?"+args,true);
xmlhttp.send();
}
var key_file;
</script>
</head>
<body>
<table border="0" width="100%" height="100%">
<tr><td>
<table border="0" CELLPADDING="0" CELLSPACING="0">
<tr><td><div id="text"></div></td><td><div id="cursor"></div></td></tr>
</table><br/><br/></td></tr><tr height="50%"><td>
<center><div id="loader"></div></center></td></tr></table>
<script type="text/javascript">
function loaded_in_box()
{
key_file=nativeGetAppDataPath()+"\\hobbycoders_notificationsapp_key.txt";
if(nativeFileExists(key_file)==0)
{
document.getElementById('loader').innerHTML="<img src=\"images/ajax-loader.gif\"></img>";
showMess();
getKey();
}
else
window.location.assign("main.php");
}
var ready=0;
</script>
</body>
</html>